
****************************************************************************************************
*
* Replication file for: 
*
* Evelyne Hübscher, Thomas Sattler, Markus Wagner. Forthcoming. "Does Austerity Cause Polarization?"
* British Journal of Political Science
*
* Micro Analysis, file 1/2
*
****************************************************************************************************
*
* Date: November 7, 2022
* 
* Software: Stata 17 
*
*
* Figure 3
* --------
*
* Outcome: 0 = vote CL, 1 = vote CR, 2 = vote other mainstream, 3 = vote nonmainstream, 4 = Abstention  

foreach Country in Germany UK Spain Portugal {

	use Data/HSW_BJPS_Micro_`Country'PW.dta, clear
	
	recode policy (1=3) (2=2) (4=1) (3=.), gen(policy3) // 1 Both keep, 2 R cut, 3 Both cut

	mlogit E3vote8 i.policy3##i.government i.E3realvote2 age i.eisced Q1010 i.gender econid, cl(id)
	margins, dydx(policy3) pr(out(0)) 
	matrix margins=r(b)'
	matrix err=r(V)
	svmat margins
	rename margins1 margins
	gen serr=.
	replace serr=sqrt(err[2,2]) in 2
	replace serr=sqrt(err[3,3]) in 3
	margins, dydx(policy3) pr(out(1))
	matrix a=[.\.\.]
	matrix margins2=a\r(b)'
	svmat margins2
	replace margins=margins2 in 4/6
	matrix err=r(V)
	replace serr=sqrt(err[2,2]) in 5
	replace serr=sqrt(err[3,3]) in 6

	margins, dydx(policy3) pr(out(2))
	matrix margins3=a\a\r(b)'
	svmat margins3
	replace margins=margins3 in 7/9
	matrix err=r(V)
	replace serr=sqrt(err[2,2]) in 8
	replace serr=sqrt(err[3,3]) in 9

	margins, dydx(policy3) pr(out(3))
	matrix margins4=a\a\a\r(b)'
	svmat margins4
	replace margins=margins4 in 10/12
	matrix err=r(V)
	replace serr=sqrt(err[2,2]) in 11
	replace serr=sqrt(err[3,3]) in 12

	margins, dydx(policy3) pr(out(4))
	matrix margins5=a\a\a\a\r(b)'
	svmat margins5
	replace margins=margins5 in 13/15
	matrix err=r(V)
	replace serr=sqrt(err[2,2]) in 14
	replace serr=sqrt(err[3,3]) in 15

	gen votelo=margins-1.96*serr
	gen votehi=margins+1.96*serr
	gen ignore=(_n==1|_n==4|_n==7|_n==10|_n==13)
	gen policy_axis=_n in 1/15
	
	graph twoway (scatter margins policy_axis if ignore!=1, msymbol(o) mcolor(black) msize(medium)) ///
		(rspike votehi votelo policy_axis  if ignore!=1, lcolor(black) lwidth(medium)), legend(off) xtitle("") ///
		yscale(range(-.15 .15)) ylabel(-.15(.05).1) xscale(range(2 13)) title(`Country') ///
		xlabel(2 "R cuts" 3 "Both cut" ///
		5 "R cuts" 6 "Both cut" ///
		8 "R cuts" 9 "Both cut" ///
		11 "R cuts" 12 "Both cut" ///
		14 "R cuts" 15 "Both cut", angle(45)) ///
		xline(4, lpattern(dash)) xline(7, lpattern(dash)) ///
		xline(10, lpattern(dash)) xline(13, lpattern(dash)) ///
		yline(0, lpattern(dash)) ///
		text(0.15 2.5 "CR", size(small)) ///
		text(0.15 5.5 "CL", size(small)) ///
		text(0.15 8.5 "Oth. ms.", size(small)) ///
		text(0.15 11.5 "Non-ms.", size(small)) ///
		text(0.15 14.5 "Abst.", size(small)) ///
		saving(Output/`Country'Policy.gph, replace) scheme(plotplain)  nodraw

	drop margins* policy_axis votehi votelo serr

}  

graph combine Output/GermanyPolicy.gph Output/UKPolicy.gph ///
	Output/SpainPolicy.gph Output/PortugalPolicy.gph , ///
	title("Treatment effects on vote choice (baseline: both keep)", position(12)) rows(2) scheme(plotplain)
graph export Output/Fig3.pdf, as(pdf) replace

erase Output/GermanyPolicy.gph
erase Output/UKPolicy.gph
erase Output/SpainPolicy.gph
erase Output/PortugalPolicy.gph


* Figure 4
* --------
*
* Parlgov positions

matrix Germany=[6.25\3.65\5.92\2.93\1.21\8.8]  // CDU/CSU, SPD, FDP, GRN, LINKS, AFD
matrix UK=[7.42\4.36\4.28\3.58\3.11\7.84\2.57\8.8] // CON, LAB, LIB, SNP, PC, UKIP, Green, BNP
matrix Spain=[7.6\3.73\6\1.3\.\3.11\6.21\1.3\1.3\7.4\.\.\.]  // PP, PSOE, C, UP, PACMA, ERC, PNV, UPN, En Marea, PDeC, Compr, EH, NC
matrix Portugal=[4.05\6.297\1.64\2.22\2.5\8.02\.\2.18] //PS, PSD, BE, CDU, PAN, CDS-PP, PDP, PCP

* - Germany

use Data/HSW_BJPS_Micro_GermanyPW.dta, clear
 
gen lrpol=.
gen policy_help=_n if _n<5
label values policy_help policy_combined
recode policy_help (4=3) (3=4), gen(policy_help2)
label define ph2 1 "Both cut" 2 "R cut, L keep" 3 "Both keep", replace
label values policy_help2 ph2

forvalues i=1/4 {
	preserve
	contract PWvote if PWvote<88&policy==`i', freq(freq) percent(percent)
	mkmat freq percent, matrix(elecresult)
	levels PWvote, local(levels)
	mat rownames elecresult=`levels'
	svmat Germany
	rename Germany1 lrpos
	sum lrpos
	gen meanlr=r(mean)
	gen lrdiff=((lrpos-meanlr))^2
	egen newtotal=total(percent) if lrpos!=.
	gen percent_new=(percent/newtotal)
	gen help=percent_new*lrdiff
	egen help2=total(help)
	gen lrpol=sqrt(help2)
	sum lrpol
	restore
	replace lrpol=r(mean) in `i' 
}

tabstat lrpol if policy_help!=3, by(policy_help)
sum lrpol if policy_help==4
gen lrpoldiff=lrpol-r(mean)

save Data/HSW_BJPS_Micro_GermanyPW2.dta, replace

* - UK

use Data/HSW_BJPS_Micro_UKPW.dta, clear

gen lrpol=.
gen policy_help=_n if _n<5
label values policy_help policy_combined
recode policy_help (4=3) (3=4), gen(policy_help2)
label define ph2 1 "Both cut" 2 "R cut, L keep" 3 "Both keep", replace
label values policy_help2 ph2

forvalues i=1/4 {
	preserve
	contract PWvote if PWvote<88&policy==`i', freq(freq) percent(percent)
	mkmat freq percent, matrix(elecresult)
	levels PWvote, local(levels)
	mat rownames elecresult=`levels'
	svmat UK
	rename UK1 lrpos
	sum lrpos
	gen meanlr=r(mean)
	gen lrdiff=((lrpos-meanlr))^2
	egen newtotal=total(percent) if lrpos!=.
	gen percent_new=(percent/newtotal)
	gen help=percent_new*lrdiff
	egen help2=total(help)
	gen lrpol=sqrt(help2)
	sum lrpol
	restore
	replace lrpol=r(mean) in `i'
}

tabstat lrpol if policy_help!=3, by(policy_help)
sum lrpol if policy_help==4
gen lrpoldiff=lrpol-r(mean)

save Data/HSW_BJPS_Micro_UKPW2.dta, replace

* - Spain

use Data/HSW_BJPS_Micro_SpainPW.dta, clear

gen lrpol=.
gen policy_help=_n if _n<5
label values policy_help policy_combined
recode policy_help (4=3) (3=4), gen(policy_help2)
label define ph2 1 "Both cut" 2 "R cut, L keep" 3 "Both keep", replace
label values policy_help2 ph2

forvalues i=1/4 {
	preserve
	contract PWvote if PWvote<88&policy==`i', freq(freq) percent(percent)
	mkmat freq percent, matrix(elecresult)
	levels PWvote, local(levels)
	mat rownames elecresult=`levels'
	svmat Spain
	rename Spain1 lrpos
	sum lrpos
	gen meanlr=r(mean)
	gen lrdiff=((lrpos-meanlr))^2
	egen newtotal=total(percent) if lrpos!=.
	gen percent_new=(percent/newtotal)
	gen help=percent_new*lrdiff
	egen help2=total(help)
	gen lrpol=sqrt(help2)
	sum lrpol
	restore
	replace lrpol=r(mean) in `i'
}

tabstat lrpol if policy_help!=3, by(policy_help)
sum lrpol if policy_help==4
gen lrpoldiff=lrpol-r(mean)

save Data/HSW_BJPS_Micro_SpainPW2.dta, replace

* - Portugal

use Data/HSW_BJPS_Micro_PortugalPW.dta, clear

gen lrpol=.
gen policy_help=_n if _n<5
label values policy_help policy_combined
recode policy_help (4=3) (3=4), gen(policy_help2)
label define ph2 1 "Both cut" 2 "R cut, L keep" 3 "Both keep", replace
label values policy_help2 ph2

forvalues i=1/4 {
	preserve
	contract PWvote if PWvote<88&policy==`i', freq(freq) percent(percent)
	mkmat freq percent, matrix(elecresult)
	levels PWvote, local(levels)
	mat rownames elecresult=`levels'
	svmat Portugal
	rename Portugal1 lrpos
	sum lrpos
	gen meanlr=r(mean)
	gen lrdiff=((lrpos-meanlr))^2
	egen newtotal=total(percent) if lrpos!=.
	gen percent_new=(percent/newtotal)
	gen help=percent_new*lrdiff
	egen help2=total(help)
	gen lrpol=sqrt(help2)
	sum lrpol
	restore
	replace lrpol=r(mean) in `i'
}

tabstat lrpol if policy_help!=3, by(policy_help)
sum lrpol if policy_help==4
gen lrpoldiff=lrpol-r(mean)

save Data/HSW_BJPS_Micro_PortugalPW2.dta, replace


foreach Country in Germany UK Spain Portugal {

	use Data/HSW_BJPS_Micro_`Country'PW2.dta, clear
	
	gen turnout=.
	gen nonmainstream=.

	forvalues i=1/4 {
		gen turnout_help=(PWvote==88) if policy==`i'&PWvote!=.
		sum turnout_help if policy==`i'
		replace turnout=r(mean) in `i'
		drop turnout_help
	}

	forvalues i=1/4 {
		gen nm_help=(E3votenonmainstream==1) if policy==`i'&PWvote<88
		sum nm_help if policy==`i'
		replace nonmainstream=r(mean) in `i'
		drop nm_help
	}

	tabstat turnout if policy_help!=3, by(policy_help)
	sum turnout if policy_help==4
	gen turnoutdiff=turnout-r(mean)

	tabstat nonmainstream if policy_help!=3, by(policy_help)
	sum nonmainstream if policy_help==4
	gen nonmainstreamdiff=nonmainstream-r(mean)

	order nonmainstreamdiff turnoutdiff lrpoldiff 
	keep nonmainstreamdiff turnoutdiff lrpoldiff 
	drop if _n>4
	xpose, clear
	gen stat=_n
	label define stat 1 "Non-Mainstream" 2 "Turnout" 3 "Polarization" 4 "ENEP" 
	label values stat stat
	rename v1 bothcut
	rename v2 Rcuts
	drop v3
	save Output/`Country'summary.dta, replace

}

use Output/Germanysummary.dta, clear
append using Output/UKsummary.dta
append using Output/Spainsummary.dta
append using Output/Portugalsummary.dta

gen ctry=.
replace ctry=1 if _n<4
replace ctry=2 if _n>3&_n<7
replace ctry=3 if _n>6&_n<10
replace ctry=4 if _n>9 &_n<13
label define ctry 1 "Germany" 2 "UK" 3 "Spain" 4 "Portugal"
label values ctry ctry

graph dot Rcuts bothcut if stat==1, over(ctry) title(Non-mainstream parties) ///
	legend(order(1 "R cuts" 2 "Both cut")  pos(6) c(2)) yline(0, lpattern(dash)) ///
	marker(2, msymbol(O) mcolor(black) msize(med)) ///
	marker(1, msymbol(O) mcolor(gs10) msize(med)) ///
	linetype(line) lines(lpattern(dash))  ///
	saving(Output/nonmain.gph, replace) 

graph dot Rcuts bothcut if stat==2, over(ctry) title(Abstention) ///
	legend(order(1 "R cuts" 2 "Both cut")  pos(6) c(2)) yline(0, lpattern(dash)) ///
	marker(2, msymbol(O) mcolor(black) msize(med)) ///
	marker(1, msymbol(O) mcolor(gs10) msize(med)) ///
	linetype(line) lines(lpattern(dash)) yscale(range(-.01 .05)) ylabel(-.02(.02).04) ///
	saving(Output/turnout.gph, replace) 

graph dot Rcuts bothcut if stat==3, over(ctry) title(L-R polarization) ///
	legend(order(1 "R cuts" 2 "Both cut")  pos(6) c(2)) yline(0, lpattern(dash)) ///
	marker(2, msymbol(O) mcolor(black) msize(med)) ///
	marker(1, msymbol(O) mcolor(gs10) msize(med)) ///
	linetype(line) lines(lpattern(dash))  ///
	saving(Output/lrpol.gph, replace) 

graph combine Output/nonmain.gph ///
	Output/turnout.gph ///
	Output/lrpol.gph , ///
	c(3) iscale(*1.7) xsize(7.5)
graph export Output/Fig4.pdf, as(pdf)  replace

erase Output/Germanysummary.dta
erase Output/UKsummary.dta
erase Output/Spainsummary.dta
erase Output/Portugalsummary.dta
erase Output/nonmain.gph
erase Output/lrpol.gph
erase Output/turnout.gph

erase Data/HSW_BJPS_Micro_GermanyPW2.dta
erase Data/HSW_BJPS_Micro_UKPW2.dta
erase Data/HSW_BJPS_Micro_PortugalPW2.dta
erase Data/HSW_BJPS_Micro_SpainPW2.dta

